var $$ = jQuery.noConflict();
(function($, doc) {
    document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + 'px';
    $.init();
    $.ready(function() {
        //获取上一页数据
        var sourceType=localStorage.getItem('sourceType')
        console.log(sourceType)
        if(sourceType!='wechat'){
            var urldata=JSON.parse(localStorage.getItem('urldata'))
        }
        var data=JSON.parse(localStorage.getItem('userInfo'))
        //form表单
        $$('#send').on('click', function() {
            var i = 0;
            mui("#formData input").each(function() {
                if(!this.value || this.value.trim() == "") {
                    var label = this.previousElementSibling;
                    mui.alert(label.innerText + "不允许为空");
                    return false;
                } else {
                    i = i + 1
                }
            });
            if (i == 4) {
                mui(this).button('loading');
                data.commanyName = $$("#formData input").eq(0).val()
                data.commanyType = $$("#formData input").eq(1).val()
                data.commanyAddress = $$("#formData input").eq(2).val()
                data.commanyPhone = $$("#formData input").eq(3).val()
                localStorage.setItem('userInfo',JSON.stringify(data))
                // var dataStr=JSON.stringify(data)
                if(sourceType=='wechat'){
                    $.ajax({
                        url:'/orderInfo/applyFromWechat',
                        data:data,
                        type:'POST',
                        headers:{"Content-Type":"application/json"},
                        success:function(res){
                            if(res.code==10010){
                                mui('#send').button('reset');
                                window.location.href='/member/success'
                            }
                            else{
                                mui('#send').button('reset');
                                mui.alert(res.message);
                            }
                            console.log(res)
                        }
                    })
                }else{
                    $.ajax({
                        url:'/orderInfo/apply'+urldata.url,
                        data:data,
                        type:'POST',
                        headers:{"Content-Type":"application/json"},
                        success:function(res){
                            if(res.code==10010){
                                mui('#send').button('reset');
                                mui.alert('1');
                                window.location.href='/member/success'
                            }else if(res.code==20018){
                                window.location.href='/member/invalid   '
                            }
                            else{
                                mui('#send').button('reset');
                                mui.alert('网站异常，请稍后重试!');
                            }
                            console.log(data)
                        }
                    })
                }
            }
        })
    });
})(mui, document);